//
//  MineFirstTableViewCell.m
//  quxiangtao
//
//  Created by xbmios on 2018/7/10.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "MineFirstTableViewCell.h"
#import "PayManageViewController.h"
#import "SetPayPasswordViewController.h"


@interface MineFirstTableViewCell ()

@property (strong, nonatomic) UILabel *blanceNumL;
@property (strong, nonatomic) UILabel *blanceL;

@property (strong, nonatomic) UIImageView *withDrawBG;
@property (strong, nonatomic) UIImageView *rechargeBG;
@property (strong, nonatomic) UILabel *withDrawL;
@property (strong, nonatomic) UILabel *rechargeL;

@end

@implementation MineFirstTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self.contentView addSubview:self.blanceNumL];
        [self.contentView addSubview:self.blanceL];
        [self.contentView addSubview:self.withDrawBG];
        [self.contentView addSubview:self.withDrawL];
        [self.contentView addSubview:self.rechargeBG];
        [self.contentView addSubview:self.rechargeL];
        
    }
    
    return self;
    
}

- (void)setUserinfoModel:(UserInfoModel *)userinfoModel {
    
    _userinfoModel = userinfoModel;
    
    if (userinfoModel.user_money.length > 0) {
        
        self.blanceNumL.text = userinfoModel.user_money;
        
    }else {
        
        self.blanceNumL.text = @"0.0";
    }
    
    
}

#pragma mark -提现
- (void)withDrawGesture:(UIGestureRecognizer *)recognizer {
    
    NSLog(@"提现");
    
    if (![[CommonAction sharedInstance] isLoginWithParentVc:self.parentVC]) {
     
        return;
    }
    
    if ([CommonUserInfo sharedInstance].is_Bind) {
        // 已绑定支付宝
        
        if ([CommonUserInfo sharedInstance].is_setPayPassword) {
            
            // 已设置支付密码
            WithDrawViewController *vc = [[WithDrawViewController alloc] init];
            [self.parentVC.navigationController pushViewController:vc animated:YES];
            
        }else {
            
            // 未设置支付密码
            SetPayPasswordViewController *vc = [[SetPayPasswordViewController alloc] init];
            [self.parentVC.navigationController pushViewController:vc animated:YES];
            
        }
        
    }else {
        
        // 未绑定支付宝
        PayManageViewController *vc = [[PayManageViewController alloc] init];
        [self.parentVC.navigationController pushViewController:vc animated:YES];
        
    }
    
}

#pragma mark -充值;
- (void)rechargeGesture:(UIGestureRecognizer *)recognizer {
    
    NSLog(@"充值");
    
    if (![[CommonAction sharedInstance] isLoginWithParentVc:self.parentVC]) {
        
        return;
    }
    
    RechargeViewController *vc = [[RechargeViewController alloc] init];
    [self.parentVC.navigationController pushViewController:vc animated:YES];

    
}


- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    __weak typeof(self) weakSelf = self;
    [self.blanceL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.contentView.mas_left).with.offset(jisuan(40));
        make.bottom.mas_equalTo(weakSelf.contentView.mas_bottom).with.offset(-jisuan(32));
    }];
    [self.blanceNumL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.contentView.mas_left).with.offset(jisuan(40));
        make.top.mas_equalTo(weakSelf.contentView.mas_top).with.offset(jisuan(30));
    }];
    
    [self.withDrawBG mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(weakSelf.contentView.mas_centerY);
        make.right.mas_equalTo(weakSelf.contentView.mas_right).with.offset(-jisuan(40));
        make.width.mas_equalTo(jisuan(108));
        make.height.mas_equalTo(jisuan(50));
    }];
    [self.withDrawL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(weakSelf.withDrawBG.mas_centerY);
        make.centerX.mas_equalTo(weakSelf.withDrawBG.mas_centerX);
    }];
    
//    [self.rechargeBG mas_makeConstraints:^(MASConstraintMaker *make) {
//        
//        make.centerY.mas_equalTo(weakSelf.contentView.mas_centerY);
//        make.right.mas_equalTo(weakSelf.contentView.mas_right).with.offset(-jisuan(40));
//        make.width.mas_equalTo(jisuan(108));
//        make.height.mas_equalTo(jisuan(50));
//        
//    }];
//    [self.rechargeL mas_makeConstraints:^(MASConstraintMaker *make) {
//        
//        make.centerY.mas_equalTo(weakSelf.rechargeBG.mas_centerY);
//        make.centerX.mas_equalTo(weakSelf.rechargeBG.mas_centerX);
//    }];
}

#pragma mark -lazy
- (UILabel *)blanceNumL {
    
    if (!_blanceNumL) {
        
        _blanceNumL = [[UILabel alloc] init];
        _blanceNumL.textAlignment = NSTextAlignmentLeft;
        _blanceNumL.textColor = Color333333;
        _blanceNumL.text = @"0.0";
        _blanceNumL.font = [UIFont fontWithName:@"DustHome" size:font(48)];
    }
    return _blanceNumL;
}

- (UILabel *)blanceL {
    
    if (!_blanceL) {
        
        _blanceL = [[UILabel alloc] init];
        _blanceL.textColor = Color999999;
        _blanceL.textAlignment = NSTextAlignmentLeft;
        _blanceL.font = Font(20);
        _blanceL.text = @"账户余额(元)";
    }
    
    return _blanceL;
    
}

- (UIImageView *)withDrawBG {
    
    if (!_withDrawBG) {
        
        _withDrawBG = [[UIImageView alloc] init];
        _withDrawBG.image = [UIImage imageNamed:@"withdrawBG"];
        _withDrawBG.contentMode = UIViewContentModeScaleAspectFit;
    
        _withDrawBG.userInteractionEnabled = YES;
        UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(withDrawGesture:)];
        [_withDrawBG addGestureRecognizer:gesture];
        
    }
    
    return _withDrawBG;
    
}

- (UILabel *)withDrawL {
    
    if (!_withDrawL) {
        
        _withDrawL = [[UILabel alloc] init];
        _withDrawL.textColor = Color333333;
        _withDrawL.text = @"提现";
        _withDrawL.textAlignment = NSTextAlignmentCenter;
        _withDrawL.font = Font(24);
        
    }
    
    return _withDrawL;
    
}


- (UIImageView *)rechargeBG {
    
    if (!_rechargeBG) {
        
        _rechargeBG = [[UIImageView alloc] init];
        _rechargeBG.image = [UIImage imageNamed:@"rechargeBg"];
        _rechargeBG.contentMode = UIViewContentModeScaleAspectFit;
        
        _rechargeBG.userInteractionEnabled = YES;
        UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rechargeGesture:)];
        [_rechargeBG addGestureRecognizer:gesture];
        
    }
    
    return _rechargeBG;
    
}
- (UILabel *)rechargeL {
    
    if (!_rechargeL) {
        
        _rechargeL = [[UILabel alloc] init];
        _rechargeL.textColor = WhiteColor;
        _rechargeL.text = @"充值";
        _rechargeL.textAlignment = NSTextAlignmentCenter;
        _rechargeL.font = Font(24);
        
    }
    
    return _rechargeL;
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
